package com.lp.utils;

import com.google.gson.Gson;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//JAVA 转Json代码
public class JsonUtil {
    public static void printJson(HttpServletResponse response, Object obj) throws IOException {
        // 返回数据，返回数据类型是json
        response.setContentType("application/json");
        // 返回数据编码UTF-8
        response.setCharacterEncoding("UTF-8");
        // 返回数据，通过gson将数据返回给Ajax 通过gson工具提高工作效率
        response.getWriter().write(new Gson().toJson(obj));
    }
}
